/*
 * CadastrodeNumerodeSerie.java
 *
 * Created on 26 de Novembro de 2008, 16:22
 */
package br.faimg.pomar.visual;

import br.faimg.pomar.controle.componentevisual.TableNumeroSerie;
import javax.swing.JTable;



/**
 *
 * @author  Juliana
 */
public class CadastrodeNumerodeSerie extends javax.swing.JInternalFrame {
      
     public CadastrodeNumerodeSerie() {
        initComponents();
        //updateTableAll();
        
        buttonGroup1.add(todosNumerosjRadioButton1);
        buttonGroup1.add(ordemdeProducaojRadioButton2);
        ordemdeProducaojRadioButton2.setSelected(true);
        

    }

    private void updateTableAll() {
        //Lista os itens cadastrados no banco na tablela
         
        TableNumeroSerie temp = new TableNumeroSerie();
        temp.setNumeroserie(null);
        temp.setOrdemProducao(null);
        tabelaNumerosJTable.setModel(new JTable(
        temp.getTableModel()
        ).getModel());
    
    }
    
        private void updateTableOrdProducao() {
        //Lista os itens cadastrados no banco na tablela
         
        TableNumeroSerie temp = new TableNumeroSerie();
        temp.setNumeroserie(null);
        temp.setOrdemProducao(Integer.parseInt(pesquisajTextField1.getText()));
        tabelaNumerosJTable.setModel(new JTable(
        temp.getTableModel()
        ).getModel());
             
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        cancelarButton = new javax.swing.JButton();
        AtualizarButton = new javax.swing.JButton();
        tabelaScrollPane = new javax.swing.JScrollPane();
        tabelaNumerosJTable = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        todosNumerosjRadioButton1 = new javax.swing.JRadioButton();
        ordemdeProducaojRadioButton2 = new javax.swing.JRadioButton();
        pesquisajTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setTitle("Consulta de Número de Série");
        setVerifyInputWhenFocusTarget(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cancelarButton.setText("Cancelar");
        cancelarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarButtonActionPerformed(evt);
            }
        });
        jPanel1.add(cancelarButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 340, 90, -1));

        AtualizarButton.setText("Atualizar");
        AtualizarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AtualizarButtonActionPerformed(evt);
            }
        });
        jPanel1.add(AtualizarButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 340, 90, -1));

        tabelaScrollPane.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaScrollPaneMouseClicked(evt);
            }
        });

        tabelaNumerosJTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabelaNumerosJTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaNumerosJTableMouseClicked(evt);
            }
        });
        tabelaScrollPane.setViewportView(tabelaNumerosJTable);

        jPanel1.add(tabelaScrollPane, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 610, 230));
        jPanel1.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 90, 610, 10));

        todosNumerosjRadioButton1.setText("Todos os números");
        todosNumerosjRadioButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                todosNumerosjRadioButton1MouseClicked(evt);
            }
        });
        jPanel1.add(todosNumerosjRadioButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 20, -1, -1));

        ordemdeProducaojRadioButton2.setText("Ordem de Produção");
        ordemdeProducaojRadioButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ordemdeProducaojRadioButton2MouseClicked(evt);
            }
        });
        jPanel1.add(ordemdeProducaojRadioButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 20, -1, -1));

        pesquisajTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                pesquisajTextField1KeyPressed(evt);
            }
        });
        jPanel1.add(pesquisajTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 30, 230, -1));

        jLabel1.setText("Número de série:");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, -1));

        jLabel2.setForeground(new java.awt.Color(255, 0, 0));
        jLabel2.setText("..");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 340, -1, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 660, 380));

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void AtualizarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AtualizarButtonActionPerformed
     
    if(pesquisajTextField1.getText().equals("") && 
            !todosNumerosjRadioButton1.isSelected() && 
            !ordemdeProducaojRadioButton2.isSelected()){
        
        jLabel2.setText("Informe os dados da pesquisa.");
        
    }
    
    if(pesquisajTextField1.getText().equals("") && ordemdeProducaojRadioButton2.isSelected()){
       jLabel2.setText("Informe uma ordem de produção."); 
    }
    
    
    
    if(todosNumerosjRadioButton1.isSelected()){
       updateTableAll();
    }
    
    if(ordemdeProducaojRadioButton2.isSelected()){
       updateTableOrdProducao();
    }
    
    

}//GEN-LAST:event_AtualizarButtonActionPerformed

private void cancelarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarButtonActionPerformed
    this.setVisible(isIcon);
}//GEN-LAST:event_cancelarButtonActionPerformed

private void tabelaScrollPaneMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaScrollPaneMouseClicked
    
}//GEN-LAST:event_tabelaScrollPaneMouseClicked

private void tabelaNumerosJTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaNumerosJTableMouseClicked
   
}//GEN-LAST:event_tabelaNumerosJTableMouseClicked

private void todosNumerosjRadioButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_todosNumerosjRadioButton1MouseClicked
       pesquisajTextField1.setEnabled(false);
       jLabel1.setEnabled(false);
       pesquisajTextField1.setText("");
       jLabel2.setText("");
}//GEN-LAST:event_todosNumerosjRadioButton1MouseClicked

private void ordemdeProducaojRadioButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ordemdeProducaojRadioButton2MouseClicked
       pesquisajTextField1.setEnabled(true);
       jLabel1.setEnabled(true);
       jLabel2.setText("");
       
}//GEN-LAST:event_ordemdeProducaojRadioButton2MouseClicked

private void pesquisajTextField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_pesquisajTextField1KeyPressed
    jLabel2.setText("");
}//GEN-LAST:event_pesquisajTextField1KeyPressed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AtualizarButton;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton cancelarButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JRadioButton ordemdeProducaojRadioButton2;
    private javax.swing.JTextField pesquisajTextField1;
    private javax.swing.JTable tabelaNumerosJTable;
    private javax.swing.JScrollPane tabelaScrollPane;
    private javax.swing.JRadioButton todosNumerosjRadioButton1;
    // End of variables declaration//GEN-END:variables
}
